package com.zhouchao.persistence.session;

import com.zhouchao.persistence.config.XMLConfigBuilder;
import com.zhouchao.persistence.pojo.Configuration;
import org.dom4j.DocumentException;

import java.beans.PropertyVetoException;
import java.io.InputStream;

/**
 * @Author: zhouchao
 * @Date: 2021/05/03 17:18
 * @Description:
 */
public class SqlSessionFactoryBuilder {

    public SqlSessionFactory build(InputStream is) throws DocumentException, PropertyVetoException {
        // 解析mybatis-config.xml文件
        XMLConfigBuilder xmlConfigBuilder = new XMLConfigBuilder();
        Configuration configuration = xmlConfigBuilder.parseConfig(is);

        // 创建SqlSessionFactory
        DefaultSqlSessionFactory sqlSessionFactory = new DefaultSqlSessionFactory(configuration);
        return sqlSessionFactory;
    }
}
